package org.example.controller;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Component("/hello")
public class HelloController implements Controller {
    @Override
    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.setViewName("/WEB-INF/hi.jsp");
        modelAndView.setViewName("hi");
        return modelAndView;
    }
//    @Override
//    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
//        //ModelAndView:包含model（数据和逻辑模型）和view（视图,比如jsp,html）
//        System.out.println("------------------handleRequest------------------");
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.addObject("message", "Hello World");
//        modelAndView.setViewName("WEB-INF/hi.jsp");
//        return modelAndView;
//    }
}
